package com.itheima.mianshi.insert;

public class InsertSort {
    public static void main(String[] args) {
        int[] a = {1, 3, 2, 5, 4, 6, 7, 8, 9, 10};
        insert(a);
    }

    /**
     * 插入排序
     *
     * @param array
     */
    public static void insert(int[] array) {
        for (int i = 1; i < array.length; i++) {
            int insertVal = array[i];
            int insertIndex = i - 1;
            while (insertIndex >= 0 && insertVal < array[insertIndex]) {
                array[insertIndex + 1] = array[insertIndex];
                insertIndex--;
            }
            array[insertIndex + 1] = insertVal;
            System.out.println("第" + i + "轮排序后的数组" + java.util.Arrays.toString(array));
        }
    }
}

